local yujie = fk.CreateSkill{
  name = "xiaobai__yujie"
}

Fk:loadTranslationTable{
  ["xiaobai__yujie"] = "预诫",
  [":xiaobai__yujie"] = "每轮限一次，一名角色的回合开始时，你可以将另一名角色（上轮以此法移出过的角色除外）于本回合移出游戏。其回到游戏时，"..
  "移出期间每有一种花色的牌被使用或打出，其便摸一张牌。",
  ["#xiaobai__yujie-choose"] = "预诫：你可以将一名角色本回合移出游戏",
  ["@@xiaobai__yujie-turn"] = "移出游戏",
  ["#xiaobai__yujie_delay"] = "预诫",

  ["$xiaobai__yujie1"] = "子志大量小，勋业难为，可不慎哉！",
  ["$xiaobai__yujie2"] = "东吴有长江之险，屡伐不遂，不如各守疆界。",
}

yujie:addEffect(fk.TurnStart,{
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(yujie.name, Player.HistoryRound) == 0 then
      local room = player.room
      local round_event = room.logic:getCurrentEvent():findParent(GameEvent.Round)
      if round_event == nil then return end
      local targets = room:getOtherPlayers(target)
      if player:getMark(yujie.name) ~= 0 then
        local id = 0
        room.logic:getEventsByRule(GameEvent.Round, 1, function (e)
          if e.id ~= round_event.id then
            id = e.id
            return true
          end
        end, 1)
        if player:getMark(yujie.name)[1] == id then
          table.removeOne(targets, room:getPlayerById(player:getMark(yujie.name)[2]))
        end
      end 
      if #targets > 0 then
        event:setCostData(self, targets)
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local targets = event:getCostData(self)
    local to = player.room:askToChoosePlayers(player, {
      max_num = 1,
      min_num = 1,
      targets = targets,
      skill_name = yujie.name,
      prompt = "#xiaobai__yujie-choose"
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1] ---@type ServerPlayer
    room:setPlayerMark(to, MarkEnum.PlayerRemoved.."-turn", 1)
    room:setPlayerMark(to, "@@xiaobai__yujie-turn", 1)
    local round_event = room.logic:getCurrentEvent():findParent(GameEvent.Round)
    if round_event == nil then return end
    room:setPlayerMark(player, yujie.name, {round_event.id, to.id})
  end,
})
yujie:addEffect(fk.TurnEnd,{
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@@xiaobai__yujie-turn") > 0 and
      (#player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        return e.data.card.suit ~= Card.NoSuit
      end, Player.HistoryTurn) > 0
      or
      #player.room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
        return e.data.card.suit ~= Card.NoSuit
      end, Player.HistoryTurn) > 0)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suits = {}
    room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      table.insertIfNeed(suits, e.data.card.suit)
    end, Player.HistoryTurn)
    room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
      table.insertIfNeed(suits, e.data.card.suit)
    end, Player.HistoryTurn)
    table.removeOne(suits, Card.NoSuit)
    player:drawCards(#suits, "xiaobai__yujie")
  end,
})


yujie:addEffect(fk.PreHpRecover, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@xiaobai__yujie-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.num = 0
  end,
})

yujie:addEffect(fk.PreHpLost, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@xiaobai__yujie-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.num = 0
  end,
})

yujie:addEffect(fk.DamageInflicted, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@xiaobai__yujie-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.damage = 0
  end,
})

yujie:addEffect("prohibit",{
  prohibit_use = function(self, player, card)
    return player:getMark("@@xiaobai__yujie-turn") ~= 0
  end,
  is_prohibited = function(self, from, to, card)
    return to:getMark("@@xiaobai__yujie-turn") ~= 0
  end,
})

return yujie